package com.hoshiibuy.sys.permission.exceptionHandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.hoshiibuy.common.exception.ServiceException;
import com.hoshiibuy.common.rpc.Response;

/**
 * 异常拦截器
 * 
 * @author Mr.wu
 *
 */
@RestControllerAdvice
public class CommonExceptionHandler {
	private final static Logger logger = LoggerFactory.getLogger(CommonExceptionHandler.class);

	/**
	 * 拦截Exception类的异常
	 * 
	 * @param e
	 * @return
	 */
	@ExceptionHandler(Exception.class)
	public Response exceptionHandler(Exception e) {
		logger.error("系统异常：" + e.getMessage());
		return Response.failed("系统异常：" + e.getMessage());
	}

	/**
	 * 
	 * @Description: 拦截服务异常
	 * @author Mr.wu
	 * @param e
	 * @return
	 * @date: 2019年4月23日 下午4:21:53
	 */
	@ExceptionHandler(ServiceException.class)
	public Response serviceExceptionHandler(Exception e) {
		logger.error("操作失败：" + e.getMessage());
		return Response.failed("操作失败：" + e.getMessage());
	}
}
